package com.zp.base.admin.common.utils;

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ZhangPeng
 * @email zhangpeng98@aliyun.com
 * @create 2021-03-05 10:59
 */
public class StringAndDateUtil {

    /**
     * 日期转字符串
     * @param date
     * @param pattern
     * @return
     */
    public static String dateToString(Date date, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }


    /**
     * 字符串转日期
     * @param date
     * @param pattern
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String date, String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.parse(date);
    }

    public static String getStringByInputStream(InputStream inputStream) {
        BufferedReader reader = null;
        String s = "";
        try {
            reader = new BufferedReader(new InputStreamReader(inputStream, "GBK"));
            while (reader.readLine() != null) {
                s += reader.readLine();
            }
            return s;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return s;
    }
}
